package com.atelier.plugin.database.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ExpandableTextField extends JPanel {
    private JTextField textField;
    private JToggleButton collapseButton;

    public ExpandableTextField() {
        setLayout(new BorderLayout());

        // 创建文本输入框
        textField = new JTextField();
        add(textField, BorderLayout.CENTER);

        // 创建折叠/展开按钮
        collapseButton = new JToggleButton("Collapse");
        collapseButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 根据按钮的状态来显示或隐藏文本框
                boolean isCollapsed = collapseButton.isSelected();
                textField.setVisible(!isCollapsed);
                if (isCollapsed) {
                    collapseButton.setText("Expand");
                } else {
                    collapseButton.setText("Collapse");
                }
            }
        });

        // 添加折叠/展开按钮到面板
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        buttonPanel.add(collapseButton);
        add(buttonPanel, BorderLayout.EAST);
    }

    // 获取文本框的文本
    public String getText() {
        return textField.getText();
    }

    // 设置文本框的文本
    public void setText(String text) {
        textField.setText(text);
    }



}
